/**
 * Created by yjj on 2017/5/3.
 */
/* eslint-disable no-return-assign */
import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';

Vue.use(Vuex);
Vue.prototype.$http = axios;

const store = new Vuex.Store({
  state: {
    user: null,
    btns: null,
    querys: null,
    fullScreen: false,
    userId: null,
    token: null,
    userType: null,
    nodes: [],
    username: null,
    realName: null,
    headUrl: null,
    currentOrganizationId: null,
    organizations: [],
    initOrganizations: [],
    initItemNames: [],
    payWayConfigs: [],
    addressDicts: [],
    initDict: {},
    customInit: [],
    currentOrganizationIds: [],
    userStatus: [{
      label: '是',
      value: true
    }, {
      label: '否',
      value: false
    }],
    stowages: [],
    total: null
  },
  getters: {
    ORGANIZATION_ATTRIBUTE: state => state.initDict['110007'],
    PARTNER_TYPE: state => state.initDict['113002'],
    LINE_TYPE: state => state.initDict['112012'],
    DIGITAL_FORMAT: state => state.initDict['112016'],
    STOWAGES: state => state.stowages,
    USER_STATUS: state => state.userStatus,
    ORGANIZATIONS: state => state.initOrganizations,
    ADDRESSDICTS: state => state.initAddressDicts,
    ITEM_NAMES: state => state.initItemNames,
    ORDER_STATUS: state => state.initDict['101001'],
    TRUCK_LOAD_ORDER_TYPE: state => state.initDict['101025'],
    TRUCK_EXCEPTION_TYPE: state => state.initDict['101035'],
    VALUE_ADDED_SERVICES: state => state.initDict['101002'],
    TAXSHEET_TYPE: state => state.initDict['102013'],
    BILLING_STATUS: state => state.initDict['102014'],
    RENDER_ACCOUNT_STATUS: state => state.initDict['102016'],
    RENDER_ACCOUNT_BILL_ITEM: state => state.initDict['102017'],
    WRITE_OFF_STATUS: state => state.initDict['102019'],
    ORDER_PAY_STATUS: state => state.initDict['101003'],
    ORDER_SOURCE: state => state.initDict['101004'],
    ORDER_COST_DETAILS: state => state.initDict['101005'], // 费用类型
    ORDER_SPONSOR: state => state.initDict['101006'],
    ORDER_CAL_METHOD: state => state.initDict['101007'],
    ORDER_COST_TYPE: state => state.initDict['101008'],
    SIGNOFF_TASK_TYPE: state => state.initDict['101009'],
    SIGNOFF_EXCEPTION_TYPE: state => state.initDict['101010'],
    ORDER_NOTICE_DELIVER_STATUS: state => state.initDict['101022'],
    ORDER_INSURANCE_STATUS: state => state.initDict['101028'],
    ORDER_INSURANCE_COMPANY_TYPE: state => state.initDict['101029'],
    PAYMENT_METHOD: state => state.initDict['102001'],
    PAY_WAY: state => state.payWayConfigs,
    TRANSACTION_STATUS: state => state.initDict['102003'],
    PAY_CARD_TYPE: state => state.initDict['102009'], // 储值卡类型
    PAY_TYPE: state => state.initDict['102004'], // 付款状态
    FUND_TRANSACTION_TYPE: state => state.initDict['103001'],
    FUNDS_RECHARGE_CHANNELS: state => state.initDict['103002'],
    FUND_TRANSACTION_STATUS: state => state.initDict['103003'],
    FUND_FLOW_TYPE: state => state.initDict['103004'],
    TRANS_PAY_TYPE: state => state.initDict['103005'],
    TRANS_TYPE: state => state.initDict['103006'],
    DISTRIBUTION_MODE: state => state.initDict['105001'],
    EMBRACE_WAY: state => state.initDict['105002'],
    TASK_TYPE: state => state.initDict['105003'],
    TASK_STATUS: state => state.initDict['105004'],
    DYNAMIC_TYPE: state => state.initDict['105005'],
    TRUCK_TYPE: state => state.initDict['105006'],
    SHIPMENT_STATUS: state => state.initDict['105007'],
    SHIPMENT_STOP_STATUS: state => state.initDict['105008'],
    SHIPMENT_TRACE_SOURCE: state => state.initDict['105009'],
    SHIPMENT_TRACE_TYPE: state => state.initDict['105010'],
    SHIPMENT_TRACE_METHOD: state => state.initDict['105011'],
    PICKUP_LOADING_EXCEPTION_TYPE: state => state.initDict['105012'],
    MEMBER_STATUS: state => state.initDict['107001'],
    MEMBER_GENDER: state => state.initDict['107002'],
    MEMBER_TYPE: state => state.initDict['107003'],
    DOCUMENT_TYPE: state => state.initDict['107004'],
    MEMBERSHIP_GRADE: state => state.initDict['107005'],
    ENTERPRISE_TYPE: state => state.initDict['107006'],
    CERTIFICATION_STATUS: state => state.initDict['107007'],
    CERTIFICATION_APPROVE_STATUS: state => state.initDict['107008'],
    PACKAGE_TYPE: state => state.initDict['109001'],
    ADDRESS_TYPE: state => state.initDict['109002'],
    INDUSTRY_TYPE: state => state.initDict['109003'],
    BANNER_TYPE: state => state.initDict['114006'],
    SMS_SEND_TYPE: state => state.initDict['114009'],
    NEWS_TYPE: state => state.initDict['114010'],
    SMS_SEND_STATUS: state => state.initDict['114008'],
    GOODS_TYPE: state => state.initDict['109004'],
    AUDIT_STATUS: state => state.initDict['109016'],
    COMPENSATION_REMIT_ACCOUNT: state => state.initDict['109017'],
    SMS_TEMPLATE_TYPE: state => state.initDict['111008'],
    LTL_SERVICE_AREA_TYPE: state => state.initDict['109005'],
    ORGANIZATION_TYPE: state => state.initDict['110001'],
    FEEDBACK_TYPE: state => state.initDict['110002'],
    TERMINAL_TYPE: state => state.initDict['110003'],
    CHANNEL_TYPE: state => state.initDict['110004'],
    VERSION_TYPE: state => state.initDict['110005'],
    MESSAGE_TYPE: state => state.initDict['111001'],
    INDICATOR: state => state.initDict['111002'],
    AUTHENTICATION_STATUS: state => state.initDict['111003'],
    MESSAGE_CLASSIFICATION: state => state.initDict['111004'],
    BANNER_FUNCTION_LIST: state => state.initDict['114007'],
    COMPANY_SIZE: state => state.initDict['111005'],
    TARIFF_RELEASE_STATUS: state => state.initDict['112001'],
    TARIFF_CLASSIFICATION: state => state.initDict['112002'],
    CARGO_NATURE: state => state.initDict['112003'],
    LIMITATION_TYPE: state => state.initDict['112004'],
    CHARGE_GRADIENT_CODE: state => state.initDict['112005'],
    AGING_CLASSIFICATION: state => state.initDict['112006'],
    FREIGHT_CALCULATION_TYPE: state => state.initDict['112007'],
    RPOVIDER_COMPANY_TYPE: state => state.initDict['104001'],
    TRUCK_LOAD_DRIVE_STATUS: state => state.initDict['104002'],
    DISCOVERY_TYPE: state => state.initDict['111006'],
    SYSTEM_SCOPE: state => state.initDict['110006'],
    LINE_TARIFF_STATUS: state => state.initDict['112008'],
    SHORT_CHARGE_GRADIENT_CODE: state => state.initDict['112009'],
    COUPON_TYPE: state => state.initDict['114001'],
    USER_ACTIVITY: state => state.initDict['114002'],
    COUPON_RELEASE_STATUS: state => state.initDict['114003'],
    COUPON_USAGE: state => state.initDict['114004'],
    NEWS_ANNOUNCEMENT_RECEIVER: state => state.initDict['114005'],
    CONNECTION_TYPE: state => state.initDict['109007'],
    CARLOAD_ORDER: state => state.initDict['101015'],
    ORDER_NUMBERS: state => state.initDict['101024'],
    VEHICLE_USAGE: state => state.initDict['109010'],
    DRIVER_PROPERTY: state => state.initDict['109012'],
    VEHICLE_PROPERTY: state => state.initDict['109013'],
    PROMISE_SERVICE_TYPE: state => state.initDict['109014'],
    INVOICE_TYPE: state => state.initDict['102012'],
    PARTNER_DIVIDED: state => state.initDict['113001'],
    ORDER_OVERALL_EVALUATION: state => state.initDict['101021'],
    TL_LENGTH_OF_VEHICLE: state => state.initDict['109008'],
    TL_VEHICLE_TYPE: state => state.initDict['109009'],
    LOADING_UNLOADING_WAY: state => state.initDict['101026'],
    MESSAGE_TEMPLATE_SCENE: state => state.initDict['115001'],
    MESSAGE_TEMPLATE_NODE: state => state.initDict['115002'],
    MESSAGE_TEMPLATE_CHANNEL: state => state.initDict['115003'],
    MESSAGE_TEMPLATE_FORM: state => state.initDict['115004'],
    MESSAGE_TEMPLATE_TARGET: state => state.initDict['115005'],
    BASE_DATA_NET_WORK_MANAGEMENT_MAPPINGMANNER: state => state.customInit = [{
      name: '按起运地',
      value: '按起运地'
    }, {name: '按目的地', value: '按目的地'}],
    BASE_DATA_NET_WORK_MANAGEMENT_NETWORKTYPE: state => state.customInit = [{
      name: '自送网点',
      value: '105002002'
    }, {name: '自提网点', value: '105001002'}, {name: '自送自提', value: '105001003'}]
  },
  mutations: {
    user (state, user) {
      state.user = user;
      state.btns = user.btns;
      state.querys = user.querys;
      state.userId = user.userid;
      state.token = user.token;
      state.nodes = user.nodes;
      state.username = user.userName;
      state.realName = user.realName;
      state.headUrl = user.headUrl;
      state.userType = user.userType;
      state.organizations = user.organizations;
      state.currentOrganizationId = user.currentOrganizationId;
      state.headersAuthorization = {'Authorization': 'Bearer ' + user.jwtToken};
      axios.defaults.headers.common['Authorization'] = 'Bearer ' + user.jwtToken;
    },
    fullScreen (state) {
      state.fullScreen = !state.fullScreen;
    },
    initOrganizations (state, reload = false) {
      if (state.initOrganizations.length === 0 || reload) {
      }
    },
    initDict (state) {
      if (Object.keys(state.initDict).length === 0) {
      }
    },
    initAddressDicts (state) {
    },
    initStowages (state) {
    },
    initItemNames (state) {
    },
    // 获取当前用户未读新闻公告数量
    getUnreadCount (state) {
    }
  }
});
let user = JSON.parse(sessionStorage.getItem('user'));
if (user != null) {
  store.commit('user', user);
}
export default store;
